package com.moonspeak.boot.logwatch;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.annotation.PreDestroy;

@EnableConfigurationProperties(LogWatchProperties.class)
public class LogWatchAutoConfiguration {

  @Autowired
  private LogWatchProperties properties;

  @PreDestroy
  public void close() {

  }

  @Bean
  public void configLogPath() {
    LogWebSocketHandle.LOG_PATH=properties.getPath();
  }

  /**
   * ServerEndpointExporter 作用
   *
   * 这个Bean会自动注册使用@ServerEndpoint注解声明的websocket endpoint
   *
   * @return
   */
  @Bean
  public ServerEndpointExporter serverEndpointExporter() {
    return new ServerEndpointExporter();
  }

  @Bean
  public LogWebSocketHandle logWebSocketHandle(){
    return new LogWebSocketHandle();
  }

}
